Skip to content

Add wasm_esm_integration_builtins compat flag for runtime-compiled Wasm - #7685

Merged
guybedford merged 1 commit into
mainfrom
gbedford/wasm-js-string-builtins
Oct 12, 2026
Merged

guybedford merged 1 commit into
mainfrom
gbedford/wasm-js-string-builtins

Conversation

@guybedford

Copy link
Copy Markdown
Contributor

This adds a wasm_esm_integration_builtins compatibility flag that compiles Wasm modules with the js-string builtins and imported string constants enabled, resolves #6811. Equivalent to the JS-visible options:

new WebAssembly.Module(src, {
  builtins: ['js-string'],
  importedStringConstants: 'wasm:js/string-constants',
});

V8 has no global flag for these; they are strictly per-module opt-in, so workerd-compiled modules (which never go through the JS constructor) couldn't use them. V8 now exposes WasmModuleObject::Compile with CompileOptions, so when the flag is set jsg::compileWasmModule passes:

options.builtins = v8::WasmModuleObject::CompileOptions::Builtins::kJsString;
options.imported_string_constants_module = "wasm:js/string-constants";

Since this is the single shared compile helper, it covers all runtime-compiled Wasm: import / import source in both module registries, and the deprecated Service Worker syntax wasmModule binding. The flag is plumbed through IsolateBase like the other module-related compat flags.

The js-string-builtins proposal is still in the implementation phase, so the flag is opt-in with no enable date.

Test coverage: adds a js-string-builtins.wat fixture importing the js-string length builtin and a "hello world" string constant, which only links if both features are enabled. new-module-registry-test (flag on) asserts constantLength() returns 11 across normal import, static import source, and dynamic import.source(), using query-distinct specifiers so each path gets its own compile. wasm-js-string-builtins-test (flag off, legacy registry) asserts the wasm:js-string import is treated as an ordinary unsupplied import.

@guybedford
guybedford requested review from a team as code owners October 10, 2026 05:03
@guybedford
guybedford requested a review from jasnell October 10, 2026 05:03
@ask-bonk

ask-bonk Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Since last review: 0 resolved, 0 still open, 0 new.
LGTM!

Not re-run: tests, api-compat, docs, compat-flags, design-simplicity, jsg-gc, kj-style, memory-safety (no author changes in their files since the last review)

Specialist findings not posted (1)
  • correctness#1 [WARNING] src/workerd/api/worker-loader.c++:247: This records the source isolate's flag, not the options that compiled this particular WebAssembly.Module. For example, a flag-enabled parent can construct the js-string Wasm with ordinary `new WebAs… — The reported metadata limitation is unchanged from the previous review and is outside this re-review's no-author-change scope.

Reviewed commit: ca2394cd · github run

Comment thread src/workerd/jsg/modules.c++
Comment thread src/workerd/api/tests/worker-loader-wasm-test.js
@guybedford
guybedford force-pushed the gbedford/wasm-js-string-builtins branch 2 times, most recently from b25c284 to 1a27ec9 Compare October 12, 2026 16:09
Compile Wasm modules with the js-string builtins and imported string
constants enabled, equivalent to the JS options
`{ builtins: ['js-string'], importedStringConstants: 'wasm:js/string-constants' }`.
These are strictly per-module opt-in in V8 with no global flag, so pass
them via WasmModuleObject::CompileOptions in jsg::compileWasmModule, which
covers all runtime-compiled Wasm: ESM import / import source in both module
registries, and the deprecated Service Worker syntax wasmModule binding.

A WebAssembly.Module passed to the worker loader carries compiled code that
bakes in the compile-time imports of the isolate that compiled it. Record
the parent's mode alongside the compiled module and recompile from the wire
bytes when the child's setting differs, in either direction, so loader-
provided modules respect the child's flag.

The proposal is still in the implementation phase, so this is gated behind
the opt-in wasm_esm_integration_builtins compat flag with no enable date.
@guybedford
guybedford force-pushed the gbedford/wasm-js-string-builtins branch from 1a27ec9 to ca2394c Compare October 12, 2026 19:25
@guybedford
guybedford enabled auto-merge (squash) October 12, 2026 19:42
@guybedford
guybedford merged commit fd1d71f into main Oct 12, 2026
25 checks passed
@guybedford
guybedford deleted the gbedford/wasm-js-string-builtins branch October 12, 2026 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants